/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * CalendarGUI.java
 *
 * Created on May 28, 2009, 5:11:46 PM
 */
package GUI;

import BUS.*;
import DTO.*;
import DTO.TasksDTO;
import java.awt.Color;
import java.awt.Component;
import java.awt.Rectangle;
import java.sql.SQLException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.DefaultCellEditor;
import javax.swing.DefaultListModel;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableCellRenderer;

/**
 *
 * @author ldtung_it
 */
public class CalendarGUI extends javax.swing.JFrame {

    Calendar calDay;
    Calendar calMonth;
    Date date;
    DateFormat dateFormat;
    DateFormat monthFormat;
    int idContact;
    ArrayList<TasksDTO> alTasksMonth;

    /** Creates new form CalendarGUI */
    public CalendarGUI() throws SQLException {
        initComponents();
         AccountMailBUS accBus = new AccountMailBUS();
        ArrayList<AccountMailDTO> lst = accBus.getListAccount();
        for (AccountMailDTO mail : lst) {
            cbAccount.addItem(mail.getAccountName());

        }
        String nameAcc = (String) this.cbAccount.getSelectedItem();
        AccountMailDTO acc = (new AccountMailBUS()).getAccountMail(nameAcc);
        idContact = acc.getId();

        /*Invisibel panel add event*/
        disableControlChildren(this.panelAddEvent);

        /*Adjust size rowClickTableMonth with table WorkMonth*/
        this.tableWorkMonth.setRowHeight(100);
        /*Set calendar is today*/
        calDay = Calendar.getInstance();
        date = new Date();
        dateFormat = new SimpleDateFormat("dd/MM/yyyy");
        calDay.setTime(date);
        this.lbNgay.setText(dateFormat.format(calDay.getTime()));


        /*Calendar month*/
        calMonth = Calendar.getInstance();
        calMonth.setTime(date);
        monthFormat = new SimpleDateFormat("MM/yyyy");
        this.lbThang.setText(monthFormat.format(calMonth.getTime()));
        if (this.tabCalendar.getSelectedIndex() == 0) {
            CalendarGUI.showTasks(calDay.getTime(), this.tableWorkDay, 0, idContact);
        } else if (this.tabCalendar.getSelectedIndex() == 1) {
            alTasksMonth = TasksBUS.getTaskMonth(calMonth.get(Calendar.MONTH) + 1, calMonth.get(Calendar.YEAR), idContact);
            this.disableDayNotBelongMonth(this.tableWorkMonth, this.calMonth);


        }
        //else if(this.tabCalendar.getSelectedIndex() == 1 )
       

    }

    private void disableControlChildren(JPanel panel) {
        for (int i = 0; i < panel.getComponentCount(); i++) {
            panel.getComponent(i).setEnabled(false);
        }

    }

    private void enableControlChildren(JPanel panel) {
        for (int i = 0; i < panel.getComponentCount(); i++) {
            panel.getComponent(i).setEnabled(true);
        }

    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jComboBox1 = new javax.swing.JComboBox();
        tabCalendar = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        tableWorkDay = new javax.swing.JTable();
        jScrollPane5 = new javax.swing.JScrollPane();
        jTable5 = new javax.swing.JTable();
        lbNgay = new javax.swing.JLabel();
        btDayBefore = new javax.swing.JButton();
        btDayAfter = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        tableWorkMonth = new javax.swing.JTable();
        lbThang = new javax.swing.JLabel();
        btMonthBefore = new javax.swing.JButton();
        btMonthAfter = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jToolBar1 = new javax.swing.JToolBar();
        btThemTask = new javax.swing.JButton();
        btXoaTask = new javax.swing.JButton();
        btSuaTask = new javax.swing.JButton();
        jPanel5 = new javax.swing.JPanel();
        cbAccount = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        panelAddEvent = new javax.swing.JPanel();
        jScrollPane6 = new javax.swing.JScrollPane();
        textEvent = new javax.swing.JTextArea();
        btThemAction = new javax.swing.JButton();
        btHuy = new javax.swing.JButton();
        spinGio = new javax.swing.JSpinner();
        spinPhut = new javax.swing.JSpinner();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jPanel3 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        lstEvents = new javax.swing.JList();
        jLabel4 = new javax.swing.JLabel();

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));

        tabCalendar.setOpaque(true);
        tabCalendar.addChangeListener(new javax.swing.event.ChangeListener() {
            public void stateChanged(javax.swing.event.ChangeEvent evt) {
                tabCalendarStateChanged(evt);
            }
        });

        tableWorkDay.setForeground(new java.awt.Color(153, 153, 0));
        tableWorkDay.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {""},
                {""},
                {""},
                {""},
                {""},
                {""},
                {""},
                {""},
                {""},
                {null},
                {null},
                {null},
                {null},
                {null},
                {null},
                {null},
                {null},
                {null},
                {null},
                {null},
                {null},
                {null},
                {null},
                {null}
            },
            new String [] {
                "Nội dung công việc trong ngày"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tableWorkDay.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tableWorkDayMouseClicked(evt);
            }
        });
        tableWorkDay.addAncestorListener(new javax.swing.event.AncestorListener() {
            public void ancestorMoved(javax.swing.event.AncestorEvent evt) {
            }
            public void ancestorAdded(javax.swing.event.AncestorEvent evt) {
                tableWorkDayAncestorAdded(evt);
            }
            public void ancestorRemoved(javax.swing.event.AncestorEvent evt) {
            }
        });
        jScrollPane1.setViewportView(tableWorkDay);

        jTable5.setBackground(new java.awt.Color(0, 204, 0));
        jTable5.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"12:00 AM"},
                {"1:00 AM"},
                {"2:00 AM"},
                {"3:00 AM"},
                {"4:00 AM"},
                {"5:00 AM"},
                {"6:00 AM"},
                {"7:00 AM"},
                {"8:00 AM"},
                {"9:00 AM"},
                {"10:00 AM"},
                {"11:00 AM"},
                {"12:00 PM"},
                {"1:00 PM"},
                {"2:00 PM"},
                {"3:00 PM"},
                {"4:00 PM"},
                {"5:00 PM"},
                {"6:00 PM"},
                {"7:00 PM"},
                {"8:00 PM"},
                {"9:00 PM"},
                {"10:00 PM"},
                {"11:00 PM"}
            },
            new String [] {
                "T.Gian"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        jTable5.setPreferredSize(new java.awt.Dimension(76, 384));
        jScrollPane5.setViewportView(jTable5);

        lbNgay.setForeground(new java.awt.Color(153, 0, 51));
        lbNgay.setText("jLabel2");

        btDayBefore.setText("<");
        btDayBefore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDayBeforeActionPerformed(evt);
            }
        });

        btDayAfter.setText(">");
        btDayAfter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btDayAfterActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(btDayBefore)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(btDayAfter)
                .addGap(124, 124, 124)
                .addComponent(lbNgay)
                .addContainerGap(213, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 87, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 384, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbNgay)
                    .addComponent(btDayBefore)
                    .addComponent(btDayAfter))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jScrollPane5, 0, 0, Short.MAX_VALUE)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 407, Short.MAX_VALUE))
                .addContainerGap(37, Short.MAX_VALUE))
        );

        tabCalendar.addTab("Day", jPanel2);

        tableWorkMonth.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {"", null, null, null, null, null, null},
                {"", null, null, null, null, null, null},
                {"", null, null, null, null, null, null},
                {"", null, null, null, null, null, null},
                {null, null, null, null, null, null, null},
                {null, null, null, null, null, null, null}
            },
            new String [] {
                "Thứ 2", "Thứ 3", "Thứ 4", "Thứ 5", "Thứ 6", "Thứ 7", "Chủ nhật"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tableWorkMonth.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tableWorkMonthMouseClicked(evt);
            }
        });
        jScrollPane3.setViewportView(tableWorkMonth);

        lbThang.setForeground(new java.awt.Color(153, 0, 51));
        lbThang.setText("jLabel4");

        btMonthBefore.setText("<");
        btMonthBefore.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btMonthBeforeActionPerformed(evt);
            }
        });

        btMonthAfter.setText(">");
        btMonthAfter.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btMonthAfterActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGap(31, 31, 31)
                .addComponent(btMonthBefore)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btMonthAfter)
                .addGap(88, 88, 88)
                .addComponent(lbThang)
                .addContainerGap(246, Short.MAX_VALUE))
            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 487, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(lbThang)
                    .addComponent(btMonthBefore)
                    .addComponent(btMonthAfter))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 444, Short.MAX_VALUE))
        );

        tabCalendar.addTab("Month", jPanel4);

        jPanel1.setBackground(new java.awt.Color(0, 153, 153));

        jToolBar1.setBorder(javax.swing.BorderFactory.createEtchedBorder());
        jToolBar1.setOrientation(1);
        jToolBar1.setRollover(true);

        btThemTask.setIcon(new javax.swing.ImageIcon(getClass().getResource("/favorites-add.png"))); // NOI18N
        btThemTask.setText("      Thêm task       ");
        btThemTask.setFocusable(false);
        btThemTask.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btThemTask.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btThemTask.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThemTaskActionPerformed(evt);
            }
        });
        jToolBar1.add(btThemTask);

        btXoaTask.setIcon(new javax.swing.ImageIcon(getClass().getResource("/delete.png"))); // NOI18N
        btXoaTask.setText("       Xóa task          ");
        btXoaTask.setToolTipText("Select task in next List to delete!");
        btXoaTask.setFocusable(false);
        btXoaTask.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btXoaTask.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btXoaTask.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btXoaTaskActionPerformed(evt);
            }
        });
        jToolBar1.add(btXoaTask);

        btSuaTask.setIcon(new javax.swing.ImageIcon(getClass().getResource("/32.png"))); // NOI18N
        btSuaTask.setText("      Sửa task          ");
        btSuaTask.setFocusable(false);
        btSuaTask.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        btSuaTask.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        btSuaTask.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btSuaTaskActionPerformed(evt);
            }
        });
        jToolBar1.add(btSuaTask);

        jPanel5.setBackground(new java.awt.Color(153, 153, 0));

        cbAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbAccountActionPerformed(evt);
            }
        });

        jLabel1.setText("My Calendar ");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGroup(jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addGap(19, 19, 19)
                        .addComponent(jLabel1))
                    .addGroup(jPanel5Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(cbAccount, 0, 269, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(cbAccount, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        panelAddEvent.setBackground(new java.awt.Color(0, 153, 153));
        panelAddEvent.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        textEvent.setColumns(20);
        textEvent.setRows(5);
        jScrollPane6.setViewportView(textEvent);

        btThemAction.setText(">>");
        btThemAction.setToolTipText("Add event");
        btThemAction.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btThemActionActionPerformed(evt);
            }
        });

        btHuy.setText("<<");
        btHuy.setToolTipText("Delete event is preparing");
        btHuy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btHuyActionPerformed(evt);
            }
        });

        jLabel2.setText("Giờ: ");

        jLabel3.setText("Phút : ");

        javax.swing.GroupLayout panelAddEventLayout = new javax.swing.GroupLayout(panelAddEvent);
        panelAddEvent.setLayout(panelAddEventLayout);
        panelAddEventLayout.setHorizontalGroup(
            panelAddEventLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jScrollPane6, javax.swing.GroupLayout.DEFAULT_SIZE, 285, Short.MAX_VALUE)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelAddEventLayout.createSequentialGroup()
                .addContainerGap(171, Short.MAX_VALUE)
                .addComponent(btHuy)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btThemAction)
                .addContainerGap())
            .addGroup(panelAddEventLayout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(spinGio, javax.swing.GroupLayout.PREFERRED_SIZE, 42, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(14, 14, 14)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(spinPhut, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(88, Short.MAX_VALUE))
        );
        panelAddEventLayout.setVerticalGroup(
            panelAddEventLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelAddEventLayout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(panelAddEventLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(spinGio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(spinPhut, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 33, Short.MAX_VALUE)
                .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(panelAddEventLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btThemAction)
                    .addComponent(btHuy)))
        );

        jPanel3.setBackground(new java.awt.Color(0, 153, 153));
        jPanel3.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        jScrollPane2.setViewportView(lstEvents);

        jLabel4.setText("Danh sách tasks :");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel4)
                .addContainerGap())
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 166, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 173, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(18, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addComponent(panelAddEvent, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel5, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jToolBar1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 215, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(panelAddEvent, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(tabCalendar, javax.swing.GroupLayout.DEFAULT_SIZE, 492, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addComponent(tabCalendar, javax.swing.GroupLayout.DEFAULT_SIZE, 501, Short.MAX_VALUE)
                .addGap(11, 11, 11))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    /**
     * add task
     * @param evt
     */
    private void btThemTaskActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThemTaskActionPerformed
        // TODO add your handling code here:
        actionAdd = true;
        actionEdit = false;
        this.enableControlChildren(this.panelAddEvent);

}//GEN-LAST:event_btThemTaskActionPerformed

    private void btXoaTaskActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btXoaTaskActionPerformed
        // TODO add your handling code here:
        if (this.tabCalendar.getSelectedIndex() == 0) {
            try {
                boolean result = this.deleteTaskByTime(calDay, lstEvents);
                if (result == true) {
                    try {
                        this.showTasks(calDay.getTime(), this.tableWorkDay, 0, idContact);
                    } catch (SQLException ex) {
                        Logger.getLogger(CalendarGUI.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
            } catch (ParseException ex) {
                Logger.getLogger(CalendarGUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (this.tabCalendar.getSelectedIndex() == 1) {
            try {
                boolean result = this.deleteTaskByTime(calMonth, lstEvents);
                alTasksMonth = TasksBUS.getTaskMonth(calMonth.get(Calendar.MONTH) + 1, calMonth.get(Calendar.YEAR), idContact);
                if (result == true) {


                    DefaultListModel dfmodelList = (DefaultListModel) this.lstEvents.getModel();

                    if (dfmodelList.size() == 0) {
                        String s = (String) this.tableWorkMonth.getValueAt(rowClickTableMonth, columnClickTableMonth);
                        int day = Integer.parseInt(StringFunctions.cutStringByChac(s, "*").get(0));
                        this.tableWorkMonth.setValueAt(day, rowClickTableMonth, columnClickTableMonth);

                    }
                }
            } catch (ParseException ex) {
                Logger.getLogger(CalendarGUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
}//GEN-LAST:event_btXoaTaskActionPerformed
    boolean actionEdit = false;
    boolean actionAdd = false;
    Calendar oldCal = Calendar.getInstance();
    private void btSuaTaskActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btSuaTaskActionPerformed
        // TODO add your handling code here:
        actionEdit = true;
        actionAdd = false;
        if (this.lstEvents.isSelectionEmpty() == false) {
            String taskIsSelected = (String) this.lstEvents.getSelectedValue();


            //delete task in database
            ArrayList<String> alTimeTask = new ArrayList<String>();
            alTimeTask = StringFunctions.cutStringByChac(taskIsSelected, "->");
            String time = alTimeTask.get(0);
            Calendar temp = Calendar.getInstance();

            String event = alTimeTask.get(1);
            event = event.substring(1, event.length());
            DateFormat dateFormat = new SimpleDateFormat("hh:mm");
            try {
                temp.setTime(dateFormat.parse(time));
                this.enableControlChildren(this.panelAddEvent);
                //only edit event, if you want to edit date, then delete that event , and add more event
                this.spinGio.setEnabled(false);
                this.spinPhut.setEnabled(false);

                this.spinGio.setValue(temp.get(Calendar.HOUR_OF_DAY));
                this.spinPhut.setValue(temp.get(Calendar.MINUTE));
                this.textEvent.setText(event);
                oldCal.setTime(calDay.getTime());
                oldCal.set(Calendar.HOUR_OF_DAY, temp.get(Calendar.HOUR_OF_DAY));
                oldCal.set(Calendar.MINUTE, temp.get(Calendar.MINUTE));

            } catch (ParseException ex) {
                Logger.getLogger(CalendarGUI.class.getName()).log(Level.SEVERE, null, ex);
            }


        } else {
            JOptionPane.showMessageDialog(null, "One Task must is selected");
        }
}//GEN-LAST:event_btSuaTaskActionPerformed
    /**
     * when click on button DayBefore, show task dayInMonth before
     * @param evt
     */
    private void btDayBeforeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDayBeforeActionPerformed
        // TODO add your handling code here:
        date = CalendarFunctions.dayBefore(calDay.getTime());
        calDay.setTime(date);

        this.lbNgay.setText(dateFormat.format(calDay.getTime()));
        try {

            CalendarGUI.showTasks(calDay.getTime(), this.tableWorkDay, 0, idContact);
        } catch (SQLException ex) {
            Logger.getLogger(CalendarGUI.class.getName()).log(Level.SEVERE, null, ex);
        }


}//GEN-LAST:event_btDayBeforeActionPerformed
    /**
     * show tasks on table
     * @param date
     * @throws java.sql.SQLException
     */
    public static void showTasks(Date date, JTable table, int column, int IDContact) throws SQLException {
        CalendarGUI.deleteContentTable(table);

        ArrayList<TasksDTO> alTask = new ArrayList<TasksDTO>();
        alTask = TasksBUS.getTask(date, IDContact);
        for (TasksDTO task : alTask) {
            Calendar calTemp = Calendar.getInstance();
            calTemp.setTime(task.getDateTask());
            int hour = calTemp.get(Calendar.HOUR_OF_DAY);
            int minute = calTemp.get(Calendar.MINUTE);

            String nowTask = "";
            String temp = (String) table.getModel().getValueAt(hour, column);
            if (temp != null) {
                nowTask += table.getModel().getValueAt(hour, column) + "; ";
            }

            nowTask += hour + ":" + minute + " -> " + task.getEvent();
            table.setValueAt(nowTask, hour, column);




        }
    }

    /**
     * clear content of table
     * @param table
     */
    public static void deleteContentTable(JTable table) {

        for (int i = 0; i < table.getRowCount(); i++) {
            for (int j = 0; j < table.getColumnCount(); j++) {
                table.setValueAt(null, i, j);
            }
        }

    }

    /**
     * when click button Day After, show task in Day After
     * @param evt
     */
    private void btDayAfterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btDayAfterActionPerformed
        // TODO add your handling code here:
        date = CalendarFunctions.dayAfter(calDay.getTime());
        calDay.setTime(date);

        this.lbNgay.setText(dateFormat.format(calDay.getTime()));
        try {
            //show task

            CalendarGUI.showTasks(calDay.getTime(), this.tableWorkDay, 0, idContact);
        } catch (SQLException ex) {
            Logger.getLogger(CalendarGUI.class.getName()).log(Level.SEVERE, null, ex);
        }

    }//GEN-LAST:event_btDayAfterActionPerformed
    private boolean deleteTaskByTime(Calendar calTemp, JList list) throws ParseException {
        if (list.isSelectionEmpty() == false) {
            String taskIsSelected = (String) list.getSelectedValue();
            DefaultListModel dflstModel = (DefaultListModel) list.getModel();
            dflstModel.remove(list.getSelectedIndex());
            //delete task in database
            ArrayList<String> alTimeTask = new ArrayList<String>();
            alTimeTask = StringFunctions.cutStringByChac(taskIsSelected, "->");
            taskIsSelected = alTimeTask.get(0);
            DateFormat dateFormat = new SimpleDateFormat("hh:mm");

            Calendar temp = Calendar.getInstance();
            temp.setTime(dateFormat.parse(taskIsSelected));
            calTemp.set(Calendar.HOUR_OF_DAY, temp.get(Calendar.HOUR_OF_DAY));
            calTemp.set(Calendar.MINUTE, temp.get(Calendar.MINUTE));
            //find a data in database and delete
            TasksBUS.deleteTask(calTemp, idContact);
            return true;
        } else {
            JOptionPane.showMessageDialog(null, "One Task must is selected");
            return false;
        }

    }

    private void addTask(JTable table) {
        int hour = Integer.parseInt(this.spinGio.getValue().toString());
        int minute = Integer.parseInt(this.spinPhut.getValue().toString());
        if (hour < 0 || hour > 23 || minute < 0 || minute > 59) {
            JOptionPane.showMessageDialog(null, "Hour must in 0-11 , Minute must in 0-23");
            return;
        }
        if (this.tabCalendar.getSelectedIndex() == 0) {
            table.setValueAt(hour + ":" + minute + "-> " + this.textEvent.getText(), hour, 0);
        }
        /*Insert event into database*/
        TasksDTO task = new TasksDTO();
        task.setIDContact(idContact);
        Calendar calTemp = Calendar.getInstance();
        if (this.tabCalendar.getSelectedIndex() == 0) {
            calTemp.setTime(calDay.getTime());
        } else if (this.tabCalendar.getSelectedIndex() == 1) {
            calTemp.setTime(calMonth.getTime());
        }
        calTemp.set(Calendar.HOUR_OF_DAY, hour);
        calTemp.set(Calendar.MINUTE, minute);
        task.setDateTask(calTemp.getTime());
        task.setEvent(this.textEvent.getText());
        //add
        TasksBUS.addTask(task);
    }

    /**
     * when button Them task is selected,
     * Add task into database
     * @param evt
     */
    private void btThemActionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btThemActionActionPerformed
        // TODO add your handling code here:
        if (actionAdd == true) {
            if (this.tabCalendar.getSelectedIndex() == 0) {
                this.addTask(this.tableWorkDay);
            } else if (this.tabCalendar.getSelectedIndex() == 1) {
                //do something
                if (this.tableWorkMonth.getSelectedRow() != -1) {
                    this.addTask(this.tableWorkMonth);
                    //load task again
                    alTasksMonth = TasksBUS.getTaskMonth(calMonth.get(Calendar.MONTH) + 1, calMonth.get(Calendar.YEAR), idContact);
                    this.disableDayNotBelongMonth(this.tableWorkMonth, this.calMonth);
                }
            }
        } else if (actionEdit == true) {
            if (this.tabCalendar.getSelectedIndex() == 0) {


                TasksBUS.updateTask(oldCal, idContact, this.textEvent.getText());
                try {
                    CalendarGUI.showTasks(calDay.getTime(), this.tableWorkDay, 0, idContact);
                    DefaultListModel dfmodelList = (DefaultListModel) this.lstEvents.getModel();
                    dfmodelList.clear();
                } catch (SQLException ex) {
                    Logger.getLogger(CalendarGUI.class.getName()).log(Level.SEVERE, null, ex);
                }
            } else if (this.tabCalendar.getSelectedIndex() == 1) {
                //do something
                //add hour ,and minute into calMonth to update event
                int hour = Integer.parseInt(this.spinGio.getValue().toString());
                int minute = Integer.parseInt(this.spinPhut.getValue().toString());
                if (hour < 0 || hour > 23 || minute < 0 || minute > 59) {
                    JOptionPane.showMessageDialog(null, "Hour must in 0-11 , Minute must in 0-23");
                    return;
                }
                calMonth.set(Calendar.HOUR_OF_DAY, hour);
                calMonth.set(Calendar.MINUTE, minute);

                //update event
                TasksBUS.updateTask(calMonth, idContact, this.textEvent.getText());
                //remove item is selected on list ,and replace by new one
                DefaultListModel dfmodelList = (DefaultListModel) this.lstEvents.getModel();
                dfmodelList.clear();
                //update task
                alTasksMonth = TasksBUS.getTaskMonth(calMonth.get(Calendar.MONTH) + 1, calMonth.get(Calendar.YEAR), idContact);
                this.disableDayNotBelongMonth(this.tableWorkMonth, this.calMonth);

            }
        }
        this.spinGio.setValue(0);
        this.spinPhut.setValue(0);
        this.textEvent.setText("");
        this.disableControlChildren(this.panelAddEvent);
    }//GEN-LAST:event_btThemActionActionPerformed
    /**
     * 
     * @param evt
     */
    private void tableWorkDayAncestorAdded(javax.swing.event.AncestorEvent evt) {//GEN-FIRST:event_tableWorkDayAncestorAdded
        // TODO add your handling code here:
    }//GEN-LAST:event_tableWorkDayAncestorAdded

    private void tableWorkDayMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableWorkDayMouseClicked
        // TODO add your handling code here:

        int column = this.tableWorkDay.getSelectedColumn();
        int row = this.tableWorkDay.getSelectedRow();
        String tasks;
        if (this.tableWorkDay.getValueAt(row, column) == null) {
            tasks = "";
        } else {
            tasks = (String) this.tableWorkDay.getValueAt(row, column);
        }
        ArrayList<String> alTasks = StringFunctions.cutStringByChac(tasks, ";");
        DefaultListModel lstModel = new DefaultListModel();
        for (String s : alTasks) {
            lstModel.addElement(s);
        }
        this.lstEvents.setModel(lstModel);
    }//GEN-LAST:event_tableWorkDayMouseClicked
    /**
     * 
     * @param evt
     */
    private void btHuyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btHuyActionPerformed
        // TODO add your handling code here:
        this.spinGio.setValue(0);
        this.spinPhut.setValue(0);
        this.textEvent.setText("");
        this.disableControlChildren(this.panelAddEvent);
    }//GEN-LAST:event_btHuyActionPerformed
    /**
     * button After is clicked
     * @param evt
     */
    private void btMonthAfterActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btMonthAfterActionPerformed
        // TODO add your handling code here:
        date = CalendarFunctions.monthAfter(this.calMonth.getTime());
        calMonth.setTime(date);
        this.lbThang.setText(monthFormat.format(calMonth.getTime()));

        DefaultTableCellRenderer dfrender = new DefaultTableCellRenderer();
        this.tableWorkMonth.setDefaultRenderer(Object.class, dfrender);

        alTasksMonth = TasksBUS.getTaskMonth(calMonth.get(Calendar.MONTH) + 1, calMonth.get(Calendar.YEAR), idContact);
        this.disableDayNotBelongMonth(this.tableWorkMonth, calMonth);

        //removeall value in listTask
        DefaultListModel dfmodelList = (DefaultListModel) this.lstEvents.getModel();
        dfmodelList.clear();
}//GEN-LAST:event_btMonthAfterActionPerformed
    /**
     * button Before is clicked
     * @param evt
     */
    private void btMonthBeforeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btMonthBeforeActionPerformed
        // TODO add your handling code here:
        date = CalendarFunctions.monthBefore(this.calMonth.getTime());
        calMonth.setTime(date);
        this.lbThang.setText(monthFormat.format(calMonth.getTime()));

        DefaultTableCellRenderer dfrender = new DefaultTableCellRenderer();
        this.tableWorkMonth.setDefaultRenderer(Object.class, dfrender);
        alTasksMonth = TasksBUS.getTaskMonth(calMonth.get(Calendar.MONTH) + 1, calMonth.get(Calendar.YEAR), idContact);
        this.disableDayNotBelongMonth(this.tableWorkMonth, calMonth);

        //removeall value in listTask
        DefaultListModel dfmodelList = (DefaultListModel) this.lstEvents.getModel();
        dfmodelList.clear();
    }//GEN-LAST:event_btMonthBeforeActionPerformed
    int value = 0;
    private void tabCalendarStateChanged(javax.swing.event.ChangeEvent evt) {//GEN-FIRST:event_tabCalendarStateChanged
        // TODO add your handling code here:

        if (value == 0) {
            value = 1;
            return;
        }

        if (this.tabCalendar.getSelectedIndex() == 0) {
            try {
                CalendarGUI.showTasks(calDay.getTime(), this.tableWorkDay, 0, idContact);
            } catch (SQLException ex) {
                Logger.getLogger(CalendarGUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        } else if (this.tabCalendar.getSelectedIndex() == 1) {
            alTasksMonth = TasksBUS.getTaskMonth(calMonth.get(Calendar.MONTH) + 1, calMonth.get(Calendar.YEAR), idContact);
            this.disableDayNotBelongMonth(this.tableWorkMonth, this.calMonth);
        }
    }//GEN-LAST:event_tabCalendarStateChanged
    int rowClickTableMonth = 0;
    int columnClickTableMonth = 0;

    /**
     * proceed event click mouse on table
     * @param evt
     */
    private void tableWorkMonthMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tableWorkMonthMouseClicked
        // TODO add your handling code here:
        DefaultListModel dflstModel = new DefaultListModel();
        this.lstEvents.setModel(dflstModel);

        rowClickTableMonth = this.tableWorkMonth.getSelectedRow();
        columnClickTableMonth = this.tableWorkMonth.getSelectedColumn();
        if (rowClickTableMonth * 7 + columnClickTableMonth >= dayBegin - 2 && rowClickTableMonth * 7 + columnClickTableMonth < maxDay + dayBegin - 2) {
            int dayCurrent = rowClickTableMonth * 7 + columnClickTableMonth - (dayBegin - 3);
            calMonth.set(Calendar.DAY_OF_MONTH, dayCurrent);
            //get tasks in day is selected


            //DefaultListModel dflstModel = new DefaultListModel();
            ArrayList<TasksDTO> alTasks = new ArrayList<TasksDTO>();
            for (TasksDTO task : this.alTasksMonth) {
                if (task.getDateTask().getDate() == calMonth.getTime().getDate() && task.getDateTask().getMonth() == calMonth.getTime().getMonth() && task.getDateTask().getYear() == calMonth.getTime().getYear()) {
                    Calendar calTemp = Calendar.getInstance();
                    calTemp.setTime(task.getDateTask());
                    int hour = calTemp.get(Calendar.HOUR_OF_DAY);
                    int minute = calTemp.get(Calendar.MINUTE);

                    String nowTask = "";

                    nowTask += hour + ":" + minute + " -> " + task.getEvent();
                    dflstModel.addElement(nowTask);

                }
            }
            this.lstEvents.setModel(dflstModel);
        //show tasks on list


        }

    }//GEN-LAST:event_tableWorkMonthMouseClicked

    private void cbAccountActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbAccountActionPerformed
        // TODO add your handling code here:
        if (value <= 1) {
            value = 2;
            return;
        }
        AccountMailBUS bus = new AccountMailBUS();
        try {
            String name = (String) cbAccount.getSelectedItem();

            AccountMailDTO mail = bus.getAccountMail(name);
            idContact = mail.getId();
            if (this.lstEvents.getModel().getSize() >= 1) {
                DefaultListModel model = (DefaultListModel) this.lstEvents.getModel();
                model.removeAllElements();
            }
            if (this.tabCalendar.getSelectedIndex() == 0) {
                CalendarGUI.showTasks(calDay.getTime(), this.tableWorkDay, 0, idContact);
            } else if (this.tabCalendar.getSelectedIndex() == 1) {
                alTasksMonth = TasksBUS.getTaskMonth(calMonth.get(Calendar.MONTH) + 1, calMonth.get(Calendar.YEAR), idContact);
                this.disableDayNotBelongMonth(this.tableWorkMonth, this.calMonth);


            }
        } catch (SQLException ex) {
            Logger.getLogger(CalendarGUI.class.getName()).log(Level.SEVERE, null, ex);
        }
    }//GEN-LAST:event_cbAccountActionPerformed
    /**
     * disabel rowClickTableMonth,columnClickTableMonth is not belong month which is considering
     * @param table
     * @param calTemp
     */
    int dayBegin = 0;
    int maxDay = 0;

    private void disableDayNotBelongMonth(JTable table, Calendar calTemp) {
        dayBegin = CalendarFunctions.dayBeginMonth(calTemp);
        if (dayBegin == 1) {
            dayBegin = 8;
        }
        JLabel label = new JLabel();
        /*Rectangle rect = table.getCellRect(1, 1, true);
        label.setSize(rect.width, rect.height);
        label.setText("1");*/


        int dayInMonth = 1;
        calMonth.set(Calendar.DATE, 1);

        Date dt = CalendarFunctions.dayBeforeSomeDay(calMonth.getTime(), dayBegin - 2);
        int dayBeforeMonth = dt.getDate();
        int dayAfterMonth = 1;
        maxDay = calTemp.getActualMaximum(Calendar.DAY_OF_MONTH);
        int count = -1;
        ArrayList<CellTable> isChangedColor = new ArrayList<CellTable>();

        for (int i = 0; i < table.getRowCount(); i++) {
            for (int j = 0; j < table.getColumnCount(); j++) {
                count++;
                if ((count < dayBegin - 2)) {
                    CellTable cell = new CellTable();
                    cell.setRow(i);
                    cell.setColumn(j);
                    isChangedColor.add(cell);
                    table.setValueAt("" + dayBeforeMonth, i, j);
                    dayBeforeMonth++;
                } else if (count >= maxDay + dayBegin - 2) {
                    CellTable cell = new CellTable();
                    cell.setRow(i);
                    cell.setColumn(j);
                    isChangedColor.add(cell);
                    table.setValueAt("" + dayAfterMonth, i, j);
                    dayAfterMonth++;
                } else {
                    table.setValueAt("" + dayInMonth, i, j);

                    ArrayList<TasksDTO> alTasks = new ArrayList<TasksDTO>();
                    /*calMonth.set(Calendar.DATE, dayInMonth);
                    try {
                    alTasks = TasksBUS.getTask(calMonth.getTime(), idContact);
                    } catch (SQLException ex) {
                    Logger.getLogger(CalendarGUI.class.getName()).log(Level.SEVERE, null, ex);
                    }*/
                    for (TasksDTO task : alTasksMonth) {
                        if (task.getDateTask().getDate() == dayInMonth) {
                            alTasks.add(task);
                        }
                    }


                    if (alTasks.size() >= 1) {
                        table.setValueAt(dayInMonth + "**Event**", i, j);
                    }
                    dayInMonth++;
                }

            }
        }

        table.setDefaultRenderer(Object.class, new TableRender(Color.LIGHT_GRAY, isChangedColor));
        table.setVisible(false);
        table.setVisible(true);


    }

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                try {
                    new CalendarGUI().setVisible(true);
                } catch (SQLException ex) {
                    Logger.getLogger(CalendarGUI.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btDayAfter;
    private javax.swing.JButton btDayBefore;
    private javax.swing.JButton btHuy;
    private javax.swing.JButton btMonthAfter;
    private javax.swing.JButton btMonthBefore;
    private javax.swing.JButton btSuaTask;
    private javax.swing.JButton btThemAction;
    private javax.swing.JButton btThemTask;
    private javax.swing.JButton btXoaTask;
    private javax.swing.JComboBox cbAccount;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JTable jTable5;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JLabel lbNgay;
    private javax.swing.JLabel lbThang;
    private javax.swing.JList lstEvents;
    private javax.swing.JPanel panelAddEvent;
    private javax.swing.JSpinner spinGio;
    private javax.swing.JSpinner spinPhut;
    private javax.swing.JTabbedPane tabCalendar;
    private javax.swing.JTable tableWorkDay;
    private javax.swing.JTable tableWorkMonth;
    private javax.swing.JTextArea textEvent;
    // End of variables declaration//GEN-END:variables
}
